#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<string.h>
#include<signal.h>
#include<sys/time.h>
#include <assert.h>




/* 
   return value: 0. readable. -1.not readable.
*/
int udetect_read(int fd, struct timeval* tv)
{
    int ret = 0;

    fd_set rfds;
    int retval;

    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);

    retval = select(fd+1, &rfds, NULL, NULL, tv);
    ret = (retval>0)?0:-1; 

    return ret;
}


/* 
   return value: 0. writeable. -1.not writeable.
*/
int udetect_write(int fd, struct timeval* tv)
{
    int ret = 0;

    fd_set wfds;
    int retval;

    FD_ZERO(&wfds);
    FD_SET(fd, &wfds);

    retval = select(fd+1, NULL, &wfds, NULL, tv);
    ret = (retval>0)?0:-1; 

    return ret;
}


